package com.borrow.jiemihua.mainUI.activity;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.borrow.jiemihua.R;
import com.borrow.jiemihua.base.BaseActivity;
import com.borrow.jiemihua.base.BaseRVAdapter;
import com.borrow.jiemihua.base.BaseViewHolder;
import com.borrow.jiemihua.base.URLConstant;
import com.borrow.jiemihua.bean.IntenlligentBean;
import com.borrow.jiemihua.utils.xutils3.MyCallBack;
import com.borrow.jiemihua.utils.xutils3.XUtil;
import com.borrow.jiemihua.view.pull.PullLoadMoreRecyclerView;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

@ContentView(R.layout.activity_intelligent_match_all)
public class IntelligentMatchActivity extends BaseActivity {
    @ViewInject(R.id.recyclerView)
    private PullLoadMoreRecyclerView recyclerView;
    private static int SXTIAOJ_YOU = 111;//筛选----参数
    private static int SXTIAOJ_WU = 110;

    //金额
    @ViewInject(R.id.tv_jebx)
    private TextView tv_jebx;
    @ViewInject(R.id.ll_jebx_bt)
    private LinearLayout ll_jebx_bt;
    //期限
    @ViewInject(R.id.tv_timebx_bt)
    private TextView tv_timebx_bt;
    @ViewInject(R.id.ll_qxbx)
    private LinearLayout ll_qxbx;
    //信用卡
    @ViewInject(R.id.ll_xyk_bt)
    private LinearLayout ll_xyk_bt;
    @ViewInject(R.id.tv_xyk)
    private TextView tv_xyk;
    //还款方式
    @ViewInject(R.id.ll_hkfs_bt)
    private LinearLayout ll_hkfs_bt;
    @ViewInject(R.id.tv_hkfs)
    private TextView tv_hkfs;
    //默认排序
    @ViewInject(R.id.ll_mrpx_bt)
    private LinearLayout ll_mrpx_bt;
    @ViewInject(R.id.tv_mrpx)
    private TextView tv_mrpx;
    //筛选
    @ViewInject(R.id.ll_sx_bt)
    private LinearLayout ll_sx_bt;
    @ViewInject(R.id.tv_xs)
    private TextView tv_xs;
    @ViewInject(R.id.tv_top_title)
    private TextView tv_top_title;

    private int textColorNor, textColorCli;
    private int textColorSXNor, textColorSXCli;
    private String typeId;
    private Map<String, Object> map = new HashMap<>();
    private List<TextView> textViews = new ArrayList<>();
    private List<TextView> textViews2 = new ArrayList<>();
    private List<TextView> textViews3 = new ArrayList<>();
    private String money;
    private String timeQX;
    private String xinYK, huanKFS, moRPX;
    private String zysf = "不限", xyqk = "不限", jkyt = "不限";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        initData();
        initView();
        setRecyclerMath();
    }

    @Override
    protected void initData() {
        typeId = getIntent().getStringExtra("typeId");
        if ("1".equals(typeId)) {
            tv_top_title.setText("下款率高");
        } else if ("2".equals(typeId)) {
            tv_top_title.setText("极速小贷");
        } else if ("3".equals(typeId)) {
            tv_top_title.setText("大额秒批");
        } else if ("4".equals(typeId)) {
            tv_top_title.setText("火爆新品");
        }
        textColorNor = getResources().getColor(R.color.black_1);
        textColorCli = getResources().getColor(R.color.main_color);
        textColorSXNor = getResources().getColor(R.color.text_9);
        textColorSXCli = getResources().getColor(R.color.white);
    }

    @Override
    protected void initView() {
        recyclerView.setLinearLayout();
    }

    @Event(value = {R.id.imgbtn_left, R.id.ll_jebx_bt, R.id.ll_qxbx, R.id.ll_xyk_bt, R.id.ll_hkfs_bt, R.id.ll_mrpx_bt, R.id.ll_sx_bt}, type = View.OnClickListener.class)
    private void getEvent(View view) {
        Intent intent = null;
        switch (view.getId()) {
            case R.id.imgbtn_left:
                finish();
                break;
            //金额不限
            case R.id.ll_jebx_bt:
                testPopupWindowType(1);
                break;
            //期限不限
            case R.id.ll_qxbx:
                testPopupWindowType(2);
                break;
            //信用卡
            case R.id.ll_xyk_bt:
                testPopupWindowType(3);
                break;
            //还款方式
            case R.id.ll_hkfs_bt:
                testPopupWindowType(4);
                break;
            //默认排序
            case R.id.ll_mrpx_bt:
                testPopupWindowType(5);
                break;
            case R.id.ll_sx_bt:
                testPopupWindowType(6);
                break;
            default:
                break;

        }
    }

    private PopupWindow mPopupWindow;

    private void testPopupWindowType(int type) {
        View contentView = null;
        if (type == 1) {
            Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_blue);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
            tv_jebx.setCompoundDrawables(null, null, drawable, null);
            tv_jebx.setTextColor(getResources().getColor(R.color.main_color));
            contentView = getPopupWindowContentView();
        } else if (type == 2) {
            Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_blue);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
            tv_timebx_bt.setCompoundDrawables(null, null, drawable, null);
            tv_timebx_bt.setTextColor(getResources().getColor(R.color.main_color));
            contentView = getPopupWindowContentView2();
        } else if (type == 3) {
            Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_blue);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
            tv_xyk.setCompoundDrawables(null, null, drawable, null);
            tv_xyk.setTextColor(getResources().getColor(R.color.main_color));
            contentView = getPopupWindowXYKView(3);
        } else if (type == 4) {
            Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_blue);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
            tv_hkfs.setCompoundDrawables(null, null, drawable, null);
            tv_hkfs.setTextColor(getResources().getColor(R.color.main_color));
            contentView = getPopupWindowXYKView(4);
        } else if (type == 5) {
            Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_blue);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
            tv_mrpx.setCompoundDrawables(null, null, drawable, null);
            tv_mrpx.setTextColor(getResources().getColor(R.color.main_color));
            contentView = getPopupWindowXYKView(5);
        } else if (type == 6) {
            Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_blue);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
            tv_xs.setCompoundDrawables(null, null, drawable, null);
            tv_xs.setTextColor(getResources().getColor(R.color.main_color));
            contentView = getPopupWindowXSTJView();
        }

        mPopupWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        // 如果不设置PopupWindow的背景，有些版本就会出现一个问题：无论是点击外部区域还是Back键都无法dismiss弹框
        mPopupWindow.setBackgroundDrawable(new ColorDrawable());
        // 设置好参数之后再show
        // popupWindow.showAsDropDown(mButton2);  // 默认在mButton2的左下角显示
        contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        if (type == 1) {
            int xOffset = ll_jebx_bt.getWidth() / 2 - contentView.getMeasuredWidth() / 2;
            mPopupWindow.showAsDropDown(ll_jebx_bt, xOffset, 0);    // 在mButton2的中间显示
            mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                    tv_jebx.setCompoundDrawables(null, null, drawable, null);
                    tv_jebx.setTextColor(getResources().getColor(R.color.black_1));
                }
            });
        } else if (type == 2) {
            int xOffset = ll_qxbx.getWidth() / 2 - contentView.getMeasuredWidth() / 2;
            mPopupWindow.showAsDropDown(ll_qxbx, xOffset, 0);    // 在mButton2的中间显示
            mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                    tv_timebx_bt.setCompoundDrawables(null, null, drawable, null);
                    tv_timebx_bt.setTextColor(getResources().getColor(R.color.black_1));
                }
            });
        } else if (type == 3) {
            int xOffset = ll_xyk_bt.getWidth() / 2 - contentView.getMeasuredWidth() / 2;
            mPopupWindow.showAsDropDown(ll_xyk_bt, xOffset, 0);    // 在mButton2的中间显示
            mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                    tv_xyk.setCompoundDrawables(null, null, drawable, null);
                    tv_xyk.setTextColor(getResources().getColor(R.color.black_1));
                }
            });
        } else if (type == 4) {
            int xOffset = ll_hkfs_bt.getWidth() / 2 - contentView.getMeasuredWidth() / 2;
            mPopupWindow.showAsDropDown(ll_hkfs_bt, xOffset, 0);    // 在mButton2的中间显示
            mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                    tv_hkfs.setCompoundDrawables(null, null, drawable, null);
                    tv_hkfs.setTextColor(getResources().getColor(R.color.black_1));
                }
            });
        } else if (type == 5) {
            int xOffset = ll_mrpx_bt.getWidth() / 2 - contentView.getMeasuredWidth() / 2;
            mPopupWindow.showAsDropDown(ll_mrpx_bt, xOffset, 0);    // 在mButton2的中间显示
            mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                    tv_mrpx.setCompoundDrawables(null, null, drawable, null);
                    tv_mrpx.setTextColor(getResources().getColor(R.color.black_1));
                }
            });
        } else if (type == 6) {
            int xOffset = ll_sx_bt.getWidth() / 2 - contentView.getMeasuredWidth() / 2;
            mPopupWindow.showAsDropDown(ll_sx_bt, xOffset, 0);    // 在mButton2的中间显示
            mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                    tv_xs.setCompoundDrawables(null, null, drawable, null);
                    tv_xs.setTextColor(getResources().getColor(R.color.black_1));
                }
            });
        }

    }

    //筛选
    private View getPopupWindowXSTJView() {
        // 一个自定义的布局，作为显示的内容
        int layoutId = R.layout.match_shaixuan_layout;   // 布局ID
        View contentView = LayoutInflater.from(this).inflate(layoutId, null);
        final TextView tv_cz = (TextView) contentView.findViewById(R.id.tv_cz);
        final TextView tv_wanc = (TextView) contentView.findViewById(R.id.tv_wanc);
        //职业身份
        final TextView tv_zy_item1 = (TextView) contentView.findViewById(R.id.tv_zy_item1);
        final TextView tv_zy_item2 = (TextView) contentView.findViewById(R.id.tv_zy_item2);
        final TextView tv_zy_item3 = (TextView) contentView.findViewById(R.id.tv_zy_item3);
        final TextView tv_zy_item4 = (TextView) contentView.findViewById(R.id.tv_zy_item4);
        final TextView tv_zy_item5 = (TextView) contentView.findViewById(R.id.tv_zy_item5);
        final TextView tv_zy_item6 = (TextView) contentView.findViewById(R.id.tv_zy_item6);
        //信用情况
        final TextView tv_xy_item1 = (TextView) contentView.findViewById(R.id.tv_xy_item1);
        final TextView tv_xy_item2 = (TextView) contentView.findViewById(R.id.tv_xy_item2);
        final TextView tv_xy_item3 = (TextView) contentView.findViewById(R.id.tv_xy_item3);
        final TextView tv_xy_item4 = (TextView) contentView.findViewById(R.id.tv_xy_item4);
        //借款用途
        final TextView tv_jk_item1 = (TextView) contentView.findViewById(R.id.tv_jk_item1);
        final TextView tv_jk_item2 = (TextView) contentView.findViewById(R.id.tv_jk_item2);
        final TextView tv_jk_item3 = (TextView) contentView.findViewById(R.id.tv_jk_item3);
        final TextView tv_jk_item4 = (TextView) contentView.findViewById(R.id.tv_jk_item4);
        final TextView tv_jk_item5 = (TextView) contentView.findViewById(R.id.tv_jk_item5);
        final TextView tv_jk_item6 = (TextView) contentView.findViewById(R.id.tv_jk_item6);
        final TextView tv_jk_item7 = (TextView) contentView.findViewById(R.id.tv_jk_item7);
        final TextView tv_jk_item8 = (TextView) contentView.findViewById(R.id.tv_jk_item8);
        //职业身份
        textViews.clear();
        textViews.add(tv_zy_item1);
        textViews.add(tv_zy_item2);
        textViews.add(tv_zy_item3);
        textViews.add(tv_zy_item4);
        textViews.add(tv_zy_item5);
        textViews.add(tv_zy_item6);
        //信用情况
        textViews2.clear();
        textViews2.add(tv_xy_item1);
        textViews2.add(tv_xy_item2);
        textViews2.add(tv_xy_item3);
        textViews2.add(tv_xy_item4);
        //借款用途
        textViews3.clear();
        textViews3.add(tv_jk_item1);
        textViews3.add(tv_jk_item2);
        textViews3.add(tv_jk_item3);
        textViews3.add(tv_jk_item4);
        textViews3.add(tv_jk_item5);
        textViews3.add(tv_jk_item6);
        textViews3.add(tv_jk_item7);
        textViews3.add(tv_jk_item8);
        View.OnClickListener menuItemOnClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    //职业身份
                    case R.id.tv_zy_item1:
                        hideTextSX(0);
                        break;
                    case R.id.tv_zy_item2:
                        hideTextSX(1);
                        break;
                    case R.id.tv_zy_item3:
                        hideTextSX(2);
                        break;
                    case R.id.tv_zy_item4:
                        hideTextSX(3);
                        break;
                    case R.id.tv_zy_item5:
                        hideTextSX(4);
                        break;
                    case R.id.tv_zy_item6:
                        hideTextSX(5);
                        break;
                    //信用情况
                    case R.id.tv_xy_item1:
                        hideTextSX2(0);
                        break;
                    case R.id.tv_xy_item2:
                        hideTextSX2(1);
                        break;
                    case R.id.tv_xy_item3:
                        hideTextSX2(2);
                        break;
                    case R.id.tv_xy_item4:
                        hideTextSX2(3);
                        break;
                    //借款用途
                    case R.id.tv_jk_item1:
                        hideTextSX3(0);
                        break;
                    case R.id.tv_jk_item2:
                        hideTextSX3(1);
                        break;
                    case R.id.tv_jk_item3:
                        hideTextSX3(2);
                        break;
                    case R.id.tv_jk_item4:
                        hideTextSX3(3);
                        break;
                    case R.id.tv_jk_item5:
                        hideTextSX3(4);
                        break;
                    case R.id.tv_jk_item6:
                        hideTextSX3(5);
                        break;
                    case R.id.tv_jk_item7:
                        hideTextSX3(6);
                        break;
                    case R.id.tv_jk_item8:
                        hideTextSX3(7);
                        break;
                    //重置
                    case R.id.tv_cz:
                        hideTextSX(0);
                        hideTextSX2(0);
                        hideTextSX3(0);
//                        CusToast.showToast(zysf+"--"+xyqk+"--"+jkyt);
                        break;
                    case R.id.tv_wanc:
//                        CusToast.showToast(zysf+"--"+xyqk+"--"+jkyt);
                        initCanShu(1, SXTIAOJ_YOU);
                        Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                        tv_xs.setCompoundDrawables(null, null, drawable, null);
                        tv_xs.setTextColor(getResources().getColor(R.color.black_1));
                        mPopupWindow.dismiss();
                        break;
                }
            }
        };
        //职业身份
        tv_zy_item1.setOnClickListener(menuItemOnClickListener);
        tv_zy_item2.setOnClickListener(menuItemOnClickListener);
        tv_zy_item3.setOnClickListener(menuItemOnClickListener);
        tv_zy_item4.setOnClickListener(menuItemOnClickListener);
        tv_zy_item5.setOnClickListener(menuItemOnClickListener);
        tv_zy_item6.setOnClickListener(menuItemOnClickListener);
        //信用情况
        tv_xy_item1.setOnClickListener(menuItemOnClickListener);
        tv_xy_item2.setOnClickListener(menuItemOnClickListener);
        tv_xy_item3.setOnClickListener(menuItemOnClickListener);
        tv_xy_item4.setOnClickListener(menuItemOnClickListener);
        //借款用途
        tv_jk_item1.setOnClickListener(menuItemOnClickListener);
        tv_jk_item2.setOnClickListener(menuItemOnClickListener);
        tv_jk_item3.setOnClickListener(menuItemOnClickListener);
        tv_jk_item4.setOnClickListener(menuItemOnClickListener);
        tv_jk_item5.setOnClickListener(menuItemOnClickListener);
        tv_jk_item6.setOnClickListener(menuItemOnClickListener);
        tv_jk_item7.setOnClickListener(menuItemOnClickListener);
        tv_jk_item8.setOnClickListener(menuItemOnClickListener);
        tv_cz.setOnClickListener(menuItemOnClickListener);
        tv_wanc.setOnClickListener(menuItemOnClickListener);
        return contentView;
    }

    //信用卡
    private View getPopupWindowXYKView(final int viewType) {
        // 一个自定义的布局，作为显示的内容
        int layoutId = R.layout.match_tiaojan_layout;   // 布局ID
        View contentView = LayoutInflater.from(this).inflate(layoutId, null);
        final TextView tv_tj_litem1 = (TextView) contentView.findViewById(R.id.tv_tj_litem1);
        final TextView tv_tj_litem2 = (TextView) contentView.findViewById(R.id.tv_tj_litem2);
        final TextView tv_tj_litem3 = (TextView) contentView.findViewById(R.id.tv_tj_litem3);
        final View vi_vlose = (View) contentView.findViewById(R.id.vi_vlose);
        if (viewType == 3) {
            tv_tj_litem1.setText("不限");
            tv_tj_litem2.setText("有信用卡");
            tv_tj_litem3.setText("无信用卡");
        } else if (viewType == 4) {
            tv_tj_litem1.setText("不限");
            tv_tj_litem2.setText("分期还款");
            tv_tj_litem3.setText("到期还款");
        } else if (viewType == 5) {
            tv_tj_litem1.setText("默认排序");
            tv_tj_litem2.setText("通过率");
            tv_tj_litem3.setText("放款速度");
        }
        textViews.clear();
        textViews.add(tv_tj_litem1);
        textViews.add(tv_tj_litem2);
        textViews.add(tv_tj_litem3);
        View.OnClickListener menuItemOnClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.tv_tj_litem1:
                        if (viewType == 3) {
                            tv_xyk.setText("不限");
                        } else if (viewType == 4) {
                            tv_hkfs.setText("不限");
                        } else if (viewType == 5) {
                            tv_mrpx.setText("默认排序");
                        }
                        hideText(0);
                        initCanShu(1, SXTIAOJ_WU);
                        break;
                    case R.id.tv_tj_litem2:
                        if (viewType == 3) {
                            tv_xyk.setText("有信用卡");
                        } else if (viewType == 4) {
                            tv_hkfs.setText("分期还款");
                        } else if (viewType == 5) {
                            tv_mrpx.setText("通过率");
                        }
                        hideText(1);
                        initCanShu(1, SXTIAOJ_WU);
                        break;
                    case R.id.tv_tj_litem3:
                        if (viewType == 3) {
                            tv_xyk.setText("无信用卡");
                        } else if (viewType == 4) {
                            tv_hkfs.setText("到期还款");
                        } else if (viewType == 5) {
                            tv_mrpx.setText("放款速度");
                        }
                        hideText(3);
                        initCanShu(1, SXTIAOJ_WU);
                        break;
                    case R.id.vi_vlose:
                        if (viewType == 3) {
                            Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                            tv_xyk.setCompoundDrawables(null, null, drawable, null);
                            tv_xyk.setTextColor(getResources().getColor(R.color.black_1));
                            mPopupWindow.dismiss();
                        } else if (viewType == 4) {
                            Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                            tv_hkfs.setCompoundDrawables(null, null, drawable, null);
                            tv_hkfs.setTextColor(getResources().getColor(R.color.black_1));
                            mPopupWindow.dismiss();
                        } else if (viewType == 5) {
                            Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                            tv_mrpx.setCompoundDrawables(null, null, drawable, null);
                            tv_mrpx.setTextColor(getResources().getColor(R.color.black_1));
                            mPopupWindow.dismiss();
                        }
                        break;
                }

                if (mPopupWindow != null) {
                    if (viewType == 3) {
                        Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                        tv_xyk.setCompoundDrawables(null, null, drawable, null);
                        tv_xyk.setTextColor(getResources().getColor(R.color.black_1));
                        mPopupWindow.dismiss();
                    } else if (viewType == 4) {
                        Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                        tv_hkfs.setCompoundDrawables(null, null, drawable, null);
                        tv_hkfs.setTextColor(getResources().getColor(R.color.black_1));
                        mPopupWindow.dismiss();
                    } else if (viewType == 5) {
                        Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                        tv_mrpx.setCompoundDrawables(null, null, drawable, null);
                        tv_mrpx.setTextColor(getResources().getColor(R.color.black_1));
                        mPopupWindow.dismiss();
                    }
                    mPopupWindow.dismiss();
                }
            }
        };
        tv_tj_litem1.setOnClickListener(menuItemOnClickListener);
        tv_tj_litem2.setOnClickListener(menuItemOnClickListener);
        tv_tj_litem3.setOnClickListener(menuItemOnClickListener);
        vi_vlose.setOnClickListener(menuItemOnClickListener);
        return contentView;
    }

    //金额不限
    private View getPopupWindowContentView() {
        // 一个自定义的布局，作为显示的内容
        int layoutId = R.layout.match_jebx_layout;   // 布局ID
        View contentView = LayoutInflater.from(this).inflate(layoutId, null);
        final TextView tv_jebx_bt = (TextView) contentView.findViewById(R.id.tv_jebx_bt);
        final TextView tv_je_litem1 = (TextView) contentView.findViewById(R.id.tv_je_litem1);
        final View vi_vlose = (View) contentView.findViewById(R.id.vi_vlose);
        textViews.clear();
        textViews.add(tv_jebx_bt);
        textViews.add(tv_je_litem1);
        View.OnClickListener menuItemOnClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.tv_jebx_bt:
                        tv_jebx.setText("金额不限");
                        hideText(0);
                        initCanShu(1, SXTIAOJ_WU);
                        break;
                    case R.id.tv_je_litem1:
                        tv_jebx.setText("100-3000");
                        hideText(1);
                        initCanShu(1, SXTIAOJ_WU);
                        break;
                    case R.id.vi_vlose:
                        Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                        tv_jebx.setCompoundDrawables(null, null, drawable, null);
                        tv_jebx.setTextColor(getResources().getColor(R.color.black_1));
                        mPopupWindow.dismiss();
                        break;
                }

                if (mPopupWindow != null) {
                    Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                    tv_jebx.setCompoundDrawables(null, null, drawable, null);
                    tv_jebx.setTextColor(getResources().getColor(R.color.black_1));
                    mPopupWindow.dismiss();
                }
            }
        };
        tv_jebx_bt.setOnClickListener(menuItemOnClickListener);
        tv_je_litem1.setOnClickListener(menuItemOnClickListener);
        vi_vlose.setOnClickListener(menuItemOnClickListener);
        return contentView;
    }

    //期限不限
    private View getPopupWindowContentView2() {
        // 一个自定义的布局，作为显示的内容
        int layoutId = R.layout.match_qxbx_layout;   // 布局ID
        View contentView = LayoutInflater.from(this).inflate(layoutId, null);
        final View vi_vlose = (View) contentView.findViewById(R.id.vi_vlose);
        final TextView tv_time_bt = (TextView) contentView.findViewById(R.id.tv_time_bt);
        final TextView tv_time_litem1 = (TextView) contentView.findViewById(R.id.tv_time_litem1);
        final TextView tv_time_litem2 = (TextView) contentView.findViewById(R.id.tv_time_litem2);
        final TextView tv_time_litem3 = (TextView) contentView.findViewById(R.id.tv_time_litem3);
        final TextView tv_time_litem4 = (TextView) contentView.findViewById(R.id.tv_time_litem4);
        final TextView tv_time_litem5 = (TextView) contentView.findViewById(R.id.tv_time_litem5);
        textViews2.clear();
        textViews2.add(tv_time_bt);
        textViews2.add(tv_time_litem1);
        textViews2.add(tv_time_litem2);
        textViews2.add(tv_time_litem3);
        textViews2.add(tv_time_litem4);
        textViews2.add(tv_time_litem5);

        View.OnClickListener menuItemOnClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.tv_time_bt:
                        tv_timebx_bt.setText("期限不限");
                        hideText2(0);
                        initCanShu(1, SXTIAOJ_WU);
                        break;
                    case R.id.tv_time_litem1:
                        tv_timebx_bt.setText("1个月内");
                        hideText2(1);
                        initCanShu(1, SXTIAOJ_WU);
                        break;
                    case R.id.tv_time_litem2:
                        tv_timebx_bt.setText("3个月内");
                        hideText2(2);
                        initCanShu(1, SXTIAOJ_WU);
                        break;
                    case R.id.tv_time_litem3:
                        tv_timebx_bt.setText("6个月内");
                        hideText2(3);
                        initCanShu(1, SXTIAOJ_WU);
                        break;
                    case R.id.tv_time_litem4:
                        tv_timebx_bt.setText("12个月内");
                        hideText2(4);
                        break;
                    case R.id.tv_time_litem5:
                        tv_timebx_bt.setText("1年以上");
                        hideText2(5);
                        initCanShu(1, SXTIAOJ_WU);
                        break;
                    case R.id.vi_vlose:
                        Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                        tv_timebx_bt.setCompoundDrawables(null, null, drawable, null);
                        tv_timebx_bt.setTextColor(getResources().getColor(R.color.black_1));
                        mPopupWindow.dismiss();
                        break;
                }
                if (mPopupWindow != null) {
                    Drawable drawable = getResources().getDrawable(R.drawable.home_screening_triangle_gray);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//对图片进行压缩
                    tv_timebx_bt.setCompoundDrawables(null, null, drawable, null);
                    tv_timebx_bt.setTextColor(getResources().getColor(R.color.black_1));
                    mPopupWindow.dismiss();
                }
            }
        };
        tv_time_bt.setOnClickListener(menuItemOnClickListener);
        tv_time_litem1.setOnClickListener(menuItemOnClickListener);
        tv_time_litem2.setOnClickListener(menuItemOnClickListener);
        tv_time_litem3.setOnClickListener(menuItemOnClickListener);
        tv_time_litem4.setOnClickListener(menuItemOnClickListener);
        tv_time_litem5.setOnClickListener(menuItemOnClickListener);
        vi_vlose.setOnClickListener(menuItemOnClickListener);
        return contentView;
    }

    private void hideTextSX(int index) {
        for (int i = 0; i < textViews.size(); i++) {
            if (i == index) {
                zysf = textViews.get(i).getText().toString();
//                CusToast.showToast(zysf);
                textViews.get(i).setTextColor(textColorSXCli);
                textViews.get(i).setBackgroundResource(R.drawable.myqiandao_button);
            } else {
                textViews.get(i).setTextColor(textColorSXNor);
                textViews.get(i).setBackgroundResource(R.drawable.shaixuan_bt);
            }

        }
    }

    private void hideTextSX2(int index) {
        for (int i = 0; i < textViews2.size(); i++) {
            if (i == index) {
                xyqk = textViews2.get(i).getText().toString();
                if (xyqk.contains("无逾期")) {
                    xyqk = "无逾期";
                } else {
                    xyqk = textViews2.get(i).getText().toString();
                }
//                CusToast.showToast(xyqk);
                textViews2.get(i).setTextColor(textColorSXCli);
                textViews2.get(i).setBackgroundResource(R.drawable.myqiandao_button);
            } else {
                textViews2.get(i).setTextColor(textColorSXNor);
                textViews2.get(i).setBackgroundResource(R.drawable.shaixuan_bt);
            }

        }
    }

    private void hideTextSX3(int index) {
        for (int i = 0; i < textViews3.size(); i++) {
            if (i == index) {
                jkyt = textViews3.get(i).getText().toString();
//                CusToast.showToast(jkyt);
                textViews3.get(i).setTextColor(textColorSXCli);
                textViews3.get(i).setBackgroundResource(R.drawable.myqiandao_button);
            } else {
                textViews3.get(i).setTextColor(textColorSXNor);
                textViews3.get(i).setBackgroundResource(R.drawable.shaixuan_bt);
            }

        }
    }

    private void hideText(int index) {
        for (int i = 0; i < textViews.size(); i++) {
            if (i == index) {
                textViews.get(i).setTextColor(textColorCli);
            } else {
                textViews.get(i).setTextColor(textColorNor);
            }

        }
    }

    private void hideText2(int index) {
        for (int i = 0; i < textViews2.size(); i++) {
            if (i == index) {
                textViews2.get(i).setTextColor(textColorCli);
            } else {
                textViews2.get(i).setTextColor(textColorNor);
            }

        }
    }

    private List<IntenlligentBean.DataBean> dataBeanList = new ArrayList<>();
    private BaseRVAdapter rvAdapter;

    //条件
    private void initCanShu(int pull, int SX_type) {
        money = tv_jebx.getText().toString();
        timeQX = tv_timebx_bt.getText().toString();
        xinYK = tv_xyk.getText().toString();
        huanKFS = tv_hkfs.getText().toString();
        moRPX = tv_mrpx.getText().toString();
        map.clear();
        if (!money.contains("不限")) {
            map.put("maxAmount", "3000");//最大额度
            map.put("minAmount", "100");//最小额度
        }
        if (!timeQX.contains("不限")) {
            if (!timeQX.contains("年")) {
                String qixian = timeQX.substring(0, 1);
                String qx = String.valueOf(Integer.parseInt(qixian) * 30);
                //还款期限
                map.put("maxRepaymentTimeLimit", qx);
            } else {
                map.put("maxRepaymentTimeLimit", "365");
            }
        }
        if (!xinYK.contains("不限")) {
            if (xinYK.equals("有信用卡")) {
                map.put("haveCreditCard", "1");//有无信用卡
            } else if (xinYK.equals("无信用卡")) {
                map.put("haveCreditCard", "2");//有无信用卡
            }
        }
        if (!huanKFS.contains("不限")) {
            if (huanKFS.equals("分期还款")) {
                map.put("repaymentWay", "1");//还款方式
            } else if (huanKFS.equals("到期还款")) {
                map.put("repaymentWay", "2");//还款方式
            }
        }
        if (!moRPX.equals("默认排序")) {
            if (moRPX.equals("放款速度")) {
                map.put("sortWay", "1");//排序
            } else if (moRPX.equals("通过率")) {
                map.put("sortWay", "2");//排序
            }
        }
        if (SX_type == 111) {
            map.put("profession", zysf);//职业身份
            map.put("credit", xyqk);//信用情况
            map.put("lendPurpose", jkyt);//借款用途
        }
        if (pull == 1) {
            upMatchData(1, map);
        } else {
            upMatchData(2, map);
        }
    }

    private void setRecyclerMath() {
        rvAdapter = new BaseRVAdapter(this, dataBeanList) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.main_recycler_item2;
            }

            @Override
            public void onBind(BaseViewHolder holder, final int position) {
                ImageView iv_main_image = holder.getImageView(R.id.iv_main_image);
                Glide.with(IntelligentMatchActivity.this).load(dataBeanList.get(position).getLogo()).into(iv_main_image);
                String maxM = String.valueOf(dataBeanList.get(position).getMaxAmount());
                String minM = String.valueOf(dataBeanList.get(position).getMinAmount());
                String manED = null;
                String minED = null;
                DecimalFormat df = new DecimalFormat("######0.0");
                if (!maxM.equals("")) {
                    if (maxM.length() >= 5) {
                        String str = String.valueOf(df.format(Double.parseDouble(maxM) / 10000));
                        int ii = Integer.parseInt(str.substring(str.length() - 1, str.length()));
                        if (ii > 0) {
                            manED = str + "万";
                        } else {
                            manED = String.valueOf(Integer.parseInt(maxM) / 10000) + "万";
                        }
//                        manED = String.valueOf(Double.parseDouble(maxM) / 10000) + "万";
                    } else if (maxM.length() == 4) {
                        String str = String.valueOf(df.format(Double.parseDouble(maxM) / 1000));
                        int ii = Integer.parseInt(str.substring(str.length() - 1, str.length()));
                        if (ii > 0) {
                            manED = str + "千";
                        } else {
                            manED = String.valueOf(Integer.parseInt(maxM) / 1000) + "千";
                        }
//                        manED = String.valueOf(Double.parseDouble(maxM) / 1000) + "千";
                    } else if (maxM.length() < 4) {
                        manED = maxM;
                    }
                }
                if (!minM.equals("")) {
                    if (minM.length() >= 5) {
                        String str = String.valueOf(df.format(Double.parseDouble(minM) / 10000));
                        int ii = Integer.parseInt(str.substring(str.length() - 1, str.length()));
                        if (ii > 0) {
                            minED = str + "万";
                        } else {
                            minED = String.valueOf(Integer.parseInt(minM) / 10000) + "万";
                        }
//                        minED = String.valueOf(Double.parseDouble(minM) / 10000) + "万";
                    } else if (minM.length() == 4) {
                        String str = String.valueOf(df.format(Double.parseDouble(minM) / 1000));
                        int ii = Integer.parseInt(str.substring(str.length() - 1, str.length()));
                        if (ii > 0) {
                            minED = str + "千";
                        } else {
                            minED = String.valueOf(Integer.parseInt(minM) / 1000) + "千";
                        }
//                        minED = String.valueOf(Double.parseDouble(minM) / 1000) + "千";
                    } else if (minM.length() < 4) {
                        minED = minM;
                    }
                }
                holder.getTextView(R.id.tv_name).setText(dataBeanList.get(position).getName());


                holder.getTextView(R.id.tv_kded).setText(minM + "元"+ "~" + maxM + "元");
                holder.getTextView(R.id.tv_lv).setText("参考利润 " + dataBeanList.get(position).getRateStr());
                holder.getTextView(R.id.tv_peonum).setText(String.valueOf(dataBeanList.get(position).getApplyForCount()));
                if (dataBeanList.get(position).getLendType() == 1) {
                    holder.getTextView(R.id.tv_dklx).setText("现金贷");
                } else if (dataBeanList.get(position).getLendType() == 2) {
                    holder.getTextView(R.id.tv_dklx).setText("信用贷");
                } else if (dataBeanList.get(position).getLendType() == 3) {
                    holder.getTextView(R.id.tv_dklx).setText("大额贷");
                }
                double time = dataBeanList.get(position).getQuickestTime() / 60;
                holder.getTextView(R.id.tv_fktime).setText(dataBeanList.get(position).getQuickestTimeStr() + "放款");
                holder.getView(R.id.ll_item_all).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(IntelligentMatchActivity.this, PlatformDetailsActivity.class)
                                .putExtra("terraceId", dataBeanList.get(position).getTerraceId() + ""));
                    }
                });
            }

        };
        recyclerView.setAdapter(rvAdapter);
        map.clear();
        initCanShu(1, SXTIAOJ_WU);
        recyclerView.setOnPullLoadMoreListener(new PullLoadMoreRecyclerView.PullLoadMoreListener() {

            @Override
            public void onRefresh() {
                map.clear();
                initCanShu(1, SXTIAOJ_WU);
            }

            @Override
            public void onLoadMore() {
                map.clear();
                initCanShu(2, SXTIAOJ_WU);
            }
        });
    }

    private int page;

    private void upMatchData(final int i, Map<String, Object> map) {
        if (i == 1) {
            page = 1;
        } else {
            page++;
        }
        map.put("typeId", typeId);
        map.put("page", page + "");
        map.put("pageSize", "12");
        map.put("showChannel", "1");
        Set keys = map.keySet();
        if (keys != null) {
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Object key = iterator.next();
                Object value = map.get(key);
                Log.e("--智能匹配参数全部--" + key, "" + value + "\n");
            }
        }
        XUtil.Post(URLConstant.PINGTAITIANJIANSX, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
//                Log.i("==智能匹配列表", result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("isSuccess");
                    if (res.equals("1")) {
                        Gson gson = new Gson();
                        IntenlligentBean intenlligentBean = gson.fromJson(result, IntenlligentBean.class);
                        List<IntenlligentBean.DataBean> dataBean = intenlligentBean.getData();
                        if (i == 1) {
                            dataBeanList.clear();
                        }
                        rvAdapter.addDataLs(dataBean);
                        rvAdapter.notifyDataSetChanged();
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                super.onFinished();
                recyclerView.setPullLoadMoreCompleted();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                ex.printStackTrace();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        map.clear();
        initCanShu(1, SXTIAOJ_WU);
    }


}
